package com.tiktok.open.sdk.core.appcheck

/*
 *  Copyright (c)  2022 TikTok Pte. Ltd. All rights reserved.
 *
 * This source code is licensed under the license found in the
 * LICENSE file in the root directory of this source tree.
 */

import android.content.Context

object TikTokAppCheckUtil {

    fun isTikTokAppInstalled(context: Context): Boolean {
        return getInstalledTikTokApp(context) != null
    }

    fun getInstalledTikTokApp(context: Context): ITikTokAppCheck? {
        for (appCheck in getAppCheckArray(context)) {
            if (appCheck.isAppInstalled()) {
                return appCheck
            }
        }
        return null
    }

    private fun getAppCheckArray(context: Context) = arrayListOf<ITikTokAppCheck>(
        object : TikTokAppCheckBase(context) {
            override val signature: String = "308203873082026fa003020102020432c7a2f7300d06092a864886f70d01010b05003074310b30090603550406130238363111300f060355040813085368616e676861693111300f060355040713085368616e6768616931183016060355040a130f6d75736963616c2e6c7920496e632e3110300e060355040b1307616e64726f6964311330110603550403130a6d75736963616c2e6c79301e170d3135303432383034323731375a170d3430303432313034323731375a3074310b30090603550406130238363111300f060355040813085368616e676861693111300f060355040713085368616e6768616931183016060355040a130f6d75736963616c2e6c7920496e632e3110300e060355040b1307616e64726f6964311330110603550403130a6d75736963616c2e6c7930820122300d06092a864886f70d01010105000382010f003082010a0282010100af12e34c0b031e41e6c99ac3b636d4253aa7584ebc9ae4c59244b02979b80969279f32e6e3dfe01a0d7cb6ed4000e8923dd90d7171a337864f6a64c590db204baab97f013fe8c7defe3cab4c16b24cb6959a3cffb9905723c0a1116d002a9cfd721c1e7a16383d47e27ed4387f8dccba6e44d5741da5cb7a295f8c32b52750c3ed5a56f494ff3d667ca3d59c9c3573bf6856677279b84d45d80c53b3a941911abbe9b15cea636abf9ba63e99b2c9ed7afa48fa2f09681fdd559f4792ecf5a26040018efaf7bd411adb0d52e2a5ad8424a776f543583a7e926c6b0337caa4aefa23f9afe52c9933a1fc6e73bc93db8d4e2ab450c2de90648dd19cd7d09c5652bf0203010001a321301f301d0603551d0e0416041422eb1a0c5448d5ffb28177f145dff7ecf6c1fe21300d06092a864886f70d01010b050003820101002f3427639582fa699602cb08659baaf722cc11ce2e29784130f6b46a5a20637eae4f19106a2433aad8433e1f3e26c2904895666f9f4f461c36f37029c251c7060d9c55453ad390375a34bb7855900238590046d7618e02a2cc91bebf9a1fadb9d220bc92c184723c366b6cbffe938bb0ae802f960f87039d1b7c613ba84282845b97fcecad7468decea3d836f7545369193df04d7406c6a02d0bf70dff36476d3d4b578c229296bf8a357049fe7e577993707d2942c4998b2335c0da96894afbd638a17d863c97f7fde2a87845f87b770200df2e8eb720ad3f4fa9fce89ea29e6cfa2fd0d3c4e7eb10f3b4a29a50dbea3bda6ff378c1d14bc009af66db0a16d2"
            override val appPackageName: String = "com.zhiliaoapp.musically"
        },
        object : TikTokAppCheckBase(context) {
            override val signature: String = "308203563082023ea00302010202044efec96a300d06092a864886f70d0101050500306d310b300906035504061302434e3110300e060355040813074265696a696e673110300e060355040713074265696a696e6731123010060355040a13094279746544616e636531123010060355040b13094279746544616e636531123010060355040313094d6963726f2043616f301e170d3131313233313038333535345a170d3339303531383038333535345a306d310b300906035504061302434e3110300e060355040813074265696a696e673110300e060355040713074265696a696e6731123010060355040a13094279746544616e636531123010060355040b13094279746544616e636531123010060355040313094d6963726f2043616f30820122300d06092a864886f70d01010105000382010f003082010a0282010100a46d108be827bff2c1ac7ad986c463b8cda9f0e7ddc21295af55bd16f7bfabb36fa33b72a8e76f5a59b48b29cb6e34c38d065589636dd120f39346c37b3753830422cc0c84243fdf0e28d3e5970dcd641c70c9e2e3ec66ac14afd351abb59d6885370e16b64bbfb28fbb234dffe25f5cfb6680c84121770cf3a177bc8a28b78b7c86d30a61eb67b9fbfd92e0c8fc5eb8346a238ddfe08522f091c622789932d9debe6910b4b903d02e5f6ded69f5c13a5d1742dac21050dfbb5f4ea615028d7a8642e4a93e075cf8f0e33a4a654af11f4f9a4905d917f0bbb84e63a1a2e90b8997f936e5bf5a75ea6d19d1d93d2677886e59e95c0bb33505363c05e10a389d0b0203010001300d06092a864886f70d010105050003820101008704e53758907db6785bec65c5f51af050873c4b0a5e08f90191b901c59969ce537942dbc9307f8fcc23b1c281a66fe46136890564f89fb16839ac69f836a9ea074eb03da8578330ab50b185bd6916f195a67036060a0bbf2aed06990e72bc4dede895ae5e695371aa4ad26efcd44b65891bda9ce02d9e71548592c2951e2cb62ed4408eec7e828ce573ffba0458341aef25957b2a76403da091322eb845b6a9903fe6aed1434012d483f1c668e2468ce129815e18283baa5e1c4209691b36ffa86506ff6a4b83f24faa744383b75968046c69703d2c5df38bad6920d9122cb1f7c78e8bfe283870359c053115e2ba0a7a03c9656a2f5a2d81f6a6fad5db2cd7"
            override val appPackageName: String = "com.ss.android.ugc.trill"
        },
    )
}
